package one.two.twelve;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Transaction {

	private String name;
	private double amount;

	public Transaction(String name, double amount) {
		this.name = name;
		this.amount = amount;
	}

	public boolean add(double a) {
		amount += a;
		return true;
	}

	public boolean retrieve(double a) {
		if (a <= amount) {
			return false;
		} else {
			amount -= a;
			return true;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || obj.getClass() != Transaction.class) {
			return false;
		}
		Transaction t = (Transaction) obj;
		if (t.getName().equals(name) && t.getAmount() == amount) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return name + ":" + amount;
	}

	public static void main(String[] args) throws Exception {

	}

}
